clear all

use FigS2data.dta


*Office Clerks 
preserve 
	local c=41
	keep is882d real`c' dhat`c'
	xtile phatbin`c'=dhat`c', nq(100)
	collapse real dhat, by(phatbin`c')

twoway	(scatter real dhat, mc(gs8)  msize(small)  saving("insample_qual_`c'_formatted.gph", replace) graphregion(margin(tiny) fcolor(white) lcolor(gs13) lwidth(vvthin) lpattern(dot)) xti("") yti(Observed frequency by bin, size(small)) ti(Office Clerks, size(medsmall) color(black))  ylabel(, labsize(small)) xlabel(, labsize(small)) ) (line dhat dhat, lc(black)), aspectratio(1) legend(off)  xsize(4) ysize(4)

	graph export "insample_qual_`c'_formatted.png", replace width(2000)
restore

*Personal Services Workers
preserve 
	local c=51
	keep is882d real`c' dhat`c'
	xtile phatbin`c'=dhat`c', nq(100)
	collapse real dhat,  by(phatbin`c')

twoway	(	scatter real dhat, mc(gs8)  msize(small)  saving("insample_qual_`c'_formatted.gph", replace) graphregion(margin(tiny) fcolor(white) lcolor(gs13) lwidth(vvthin) lpattern(dot))  xti("") yti("") ti(Personal Services Workers, size(medsmall) color(black))  ylabel(, labsize(small)) xlabel(, labsize(small)) ) (line dhat dhat, lc(black)), aspectratio(1) legend(off)  xsize(4) ysize(4)
 
	graph export "insample_qual_`c'_formatted.png", replace width(2000)
restore

*Associate Professionals
preserve 
	local c=34
	keep is882d real`c' dhat`c'
	xtile phatbin`c'=dhat`c', nq(100)
	collapse real dhat,  by(phatbin`c')

twoway	(	scatter real dhat, mc(gs8)  msize(small)  saving("insample_qual_`c'_formatted.gph", replace) graphregion(margin(tiny) fcolor(white) lcolor(gs13) lwidth(vvthin) lpattern(dot)) xti("") yti("") ti(Associate Professionals, size(medsmall) color(black))  ylabel(, labsize(small))  xlabel(, labsize(small)) ) (line dhat dhat, lc(black)), aspectratio(1) legend(off)  xsize(4) ysize(4)

	graph export "insample_qual_`c'_formatted.png", replace width(2000)
restore

*Extraction and building workers 
preserve 
	local c=71
	keep is882d real`c' dhat`c'
	xtile phatbin`c'=dhat`c', nq(100)
	collapse real dhat,  by(phatbin`c')

twoway	(	scatter real dhat, mc(gs8)  msize(small)  saving("insample_qual_`c'_formatted.gph", replace) graphregion(margin(tiny) fcolor(white) lcolor(gs13) lwidth(vvthin) lpattern(dot)) xti(Estimated Probability, size(small)) yti(Observed frequency by bin, size(small)) ti(Extraction and Building Workers, size(medsmall) color(black) )  ylabel(, labsize(small)) xlabel(, labsize(small)) ) (line dhat dhat, lc(black)), aspectratio(1) legend(off)  xsize(4) ysize(4)

	graph export "insample_qual_`c'_formatted.png", replace width(2000)
restore


*Skilled agricultural and fishery workers 
preserve 
	local c=61
	keep is882d real`c' dhat`c'
	xtile phatbin`c'=dhat`c', nq(100)
	collapse real dhat,  by(phatbin`c')

twoway	(	scatter real dhat, mc(gs8)  msize(small)  saving("insample_qual_`c'_formatted.gph", replace) graphregion(margin(tiny) fcolor(white) lcolor(gs13) lwidth(vvthin) lpattern(dot)) xti(Estimated Probability, size(small)) yti("") ti(Skilled Agricultural Workers, size(medsmall) color(black) )  ylabel(, labsize(small)) xlabel(, labsize(small)) ) (line dhat dhat, lc(black)), aspectratio(1) legend(off)  xsize(4) ysize(4)

	graph export "insample_qual_`c'_formatted.png", replace width(2000)
restore


*Metal, machinery and related trades workers 
preserve 
	local c=72
	keep is882d real`c' dhat`c'
	xtile phatbin`c'=dhat`c', nq(100)
	collapse real dhat,  by(phatbin`c')

twoway	(	scatter real dhat, mc(gs8)  msize(small)  saving("insample_qual_`c'_formatted.gph", replace) graphregion(margin(tiny) fcolor(white) lcolor(gs13) lwidth(vvthin) lpattern(dot)) xti(Estimated Probability, size(small)) yti("") ti(Metal and Machinery Workers, size(medsmall) color(black) )  ylabel(, labsize(small)) xlabel(, labsize(small)) ) (line dhat dhat, lc(black)), aspectratio(1) legend(off)  xsize(4) ysize(4)

	graph export "insample_qual_`c'_formatted.png", replace width(2000)
restore

 
	graph combine insample_qual_41_formatted.gph insample_qual_51_formatted.gph insample_qual_34_formatted.gph insample_qual_71_formatted.gph insample_qual_61_formatted.gph insample_qual_72_formatted.gph,  saving(insample_qual_formatted.gph, replace )  graphregion(margin(small) fcolor(white) lcolor(white)) 
	graph export "FigS1.eps", replace 
